from django.db import models
from users.models import Users
import django.utils.timezone

# Create your models here.

'''
本模型中涉及到的物理学计量单位说明如下：
功率：kW
气体：m^3/h
压强：kPa.G
容量：L
'''


class ICE(models.Model):
    """
    内燃机 Internal combustion engine
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_power = models.FloatField()  # 最大功率
    heat_production = models.FloatField()  # 产热量
    power_generation = models.FloatField()  # 发电量
    heat_effect = models.FloatField()  # 热效率
    power_effect = models.FloatField()  # 电效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "max_power": "最大功率(kW)",
            "heat_production": "产热量(kW)",
            "power_generation": "发电量(kW)",
            "heat_effect": "热效率(%)",
            "power_effect": "电效率(%)",
            "ppp": "单位功率费用(元/kW)"
        }


class GasBoiler(models.Model):
    """
    燃气锅炉
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_in_power = models.FloatField()  # 额定输入功率
    out_power = models.FloatField()  # 输出功率
    heat_effect = models.FloatField()  # 热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "max_in_power": "额定输入功率(kW)",
            "out_power": "输出功率(kW)",
            "heat_effect": "热效率(%)",
            "ppp": "单位功率费用(元/kW)"
        }


class ElectricBoiler(models.Model):
    """
    电锅炉
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_in_power = models.FloatField()  # 额定输入功率
    max_out_power = models.FloatField()  # 额定输出功率
    heat_effect = models.FloatField()  # 热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "max_in_power": "额定输入功率(kW)",
            "max_out_power": "额定输出功率(kW)",
            "heat_effect": "热效率(%)",
            "ppp": "单位功率费用(元/kW)"
        }


class AR(models.Model):
    """
    直燃型制冷机 Absorption refrigerator 单独使用时使用
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    cool_cap = models.FloatField()  # 制冷量
    heat_cap = models.FloatField()  # 供热量
    pay_to_cool = models.FloatField()  # 耗量（制冷）
    pay_to_heat = models.FloatField()  # 耗量（制热）
    income_cool = models.FloatField()  # 制冷输入功率
    income_heat = models.FloatField()  # 制热输入功率
    heat_effect = models.FloatField()  # 制热效率
    cool_effect = models.FloatField()  # 制冷效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "cool_cap": "制冷量(kW)",
            "heat_cap": "供热量(kW)",
            "pay_to_cool": "耗量（制冷）(m³/h)",
            "pay_to_heat": "耗量（制热）(m³/h)",
            "income_cool": "制冷输入功率(kW)",
            "income_heat": "制热输入功率(kW)",
            "heat_effect": "制热效率(%)",
            "cool_effect": "制冷效率(%)",
            "ppp": "单位功率费用(元/kW)"
        }


class ARS(models.Model):
    """
    Absorption refrigerator 三联供系统中使用的
    烟气热水机
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    cool_cap = models.FloatField()  # 制冷量
    effect = models.FloatField(default=0.76)  # 制冷效率
    input_power = models.FloatField()  # 输入功率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "cool_cap": "制冷量(kW)",
            "effect": "制冷效率(%)",
            "input_power": "输入功率(kW)",
            "ppp": "单位功率费用(元/kW)"
        }


class IceTank(models.Model):
    """
    蓄冰槽
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    heat_capacity = models.FloatField()  # 蓄冰潜热容量kW
    storage = models.FloatField()  # 蓄冰槽容量
    effect = models.FloatField()  # 充放能效率
    max_prop = models.FloatField()  # 储能占比上限
    min_prop = models.FloatField()  # 储能占比下限
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "heat_capacity": "蓄冰潜热容量(kW)",
            "storage": "蓄冰槽容量(L)",
            "effect": "充放能效率",
            "max_prop": "储能占比上限",
            "min_prop": "储能占比下限",
            "ppp": "单位功率费用(元/kW)"
        }


class ERU(models.Model):
    """
    电制冷机组 Electric refrigeration unit
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    ice_effect = models.FloatField()  # 制冰效率
    cool_effect = models.FloatField()  # 制冷效率
    power_to_ice = models.FloatField()  # 制冰功率
    power_to_cool = models.FloatField()  # 制冷功率
    input_ice_power = models.FloatField()  # 制冰输入功率
    input_cool_power = models.FloatField()  # 制冷输入功率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "ice_effect": "制冰效率",
            "cool_effect": "制冷效率",
            "power_to_ice": "制冰功率(kW)",
            "power_to_cool": "制冷功率(kW)",
            "input_ice_power": "制冰输入功率(kW)",
            "input_cool_power": "制冷输入功率(kW)",
            "ppp": "单位功率费用(元/kW)"
        }


class AirPump(models.Model):
    """
    风冷热泵 Air cooled heat pump
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    make_cool_power = models.FloatField()  # 制冷量
    input_power = models.FloatField()  # 制冷输入功率
    effect = models.FloatField()  # 制冷效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)
    output_heat_power = models.FloatField(default=0)  # 输出热量
    input_heat_power = models.FloatField(default=0)  # 制热输入功率
    make_heat_effect = models.FloatField(default=0)  # 制热效率

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "make_cool_power": "制冷量(kW)",
            "input_power": "制冷输入功率(kW)",
            "effect": "制冷效率",
            "output_heat_power": "输出热量(kW)",
            "input_heat_power": "制热输入功率(kW)",
            "make_heat_effect": "制热效率",
            "ppp": "单位功率费用(元/kW)"
        }


class GroundPump(models.Model):
    """
    地源热泵 Ground source heat pump
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    output_cool_power = models.FloatField()  # 输出冷量
    input_cool_power = models.FloatField()  # 制冷输入功率
    make_cool_effect = models.FloatField()  # 制冷效率
    output_heat_power = models.FloatField()  # 输出热量
    input_heat_power = models.FloatField()  # 制热输入功率
    make_heat_effect = models.FloatField()  # 制热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "output_cool_power": "输出冷量(kW)",
            "input_cool_power": "制冷输入功率(kW)",
            "make_cool_effect": "制冷效率",
            "output_heat_power": "输出热量(kW)",
            "input_heat_power": "制热输入功率(kW)",
            "make_heat_effect": "制热效率",
            "ppp": "单位功率费用(元/kW)"
        }


class GasTurbine(models.Model):
    """
    燃气轮机
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    input_power = models.FloatField()  # 输入功率
    generation_power = models.FloatField()  # 发电功率
    generation_effect = models.FloatField()  # 发电效率
    waste_heat = models.FloatField()  # 余热
    heat_effect = models.FloatField()  # 热效率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "input_power": "输入功率(kW)",
            "generation_power": "发电功率(kW)",
            "generation_effect": "发电效率",
            "waste_heat": "余热(kW)",
            "heat_effect": "热效率(kW)",
            "ppp": "单位功率费用(元/kW)"
        }


class WindPower(models.Model):
    """
    风力发电
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    s2 = models.FloatField(default=0)  # 风速2.5处理
    s3 = models.FloatField(default=0)  # 风速N出力，默认为0，为不出力
    s4 = models.FloatField(default=0)
    s5 = models.FloatField(default=0)
    s6 = models.FloatField(default=0)
    s7 = models.FloatField(default=0)
    s8 = models.FloatField(default=0)
    s9 = models.FloatField(default=0)
    s10 = models.FloatField(default=0)
    s11 = models.FloatField(default=0)
    s12 = models.FloatField(default=0)
    s13 = models.FloatField(default=0)
    s14 = models.FloatField(default=0)
    s15 = models.FloatField(default=0)
    s16 = models.FloatField(default=0)
    s17 = models.FloatField(default=0)
    s18 = models.FloatField(default=0)
    s19 = models.FloatField(default=0)
    s20 = models.FloatField(default=0)
    s21 = models.FloatField(default=0)
    s22 = models.FloatField(default=0)
    s23 = models.FloatField(default=0)
    s24 = models.FloatField(default=0)
    s25 = models.FloatField(default=0)
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "s2": "风速2.5出力(kW)",
            "s3": "风速3出力(kW)",
            "s4": "风速4出力(kW)",
            "s5": "风速5出力(kW)",
            "s6": "风速6出力(kW)",
            "s7": "风速7出力(kW)",
            "s8": "风速8出力(kW)",
            "s9": "风速9出力(kW)",
            "s10": "风速10出力(kW)",
            "s11": "风速11出力(kW)",
            "s12": "风速12出力(kW)",
            "s13": "风速13出力(kW)",
            "s14": "风速14出力(kW)",
            "s15": "风速15出力(kW)",
            "s16": "风速16出力(kW)",
            "s17": "风速17出力(kW)",
            "s18": "风速18出力(kW)",
            "s19": "风速19出力(kW)",
            "s20": "风速20出力(kW)",
            "s21": "风速21出力(kW)",
            "s22": "风速22出力(kW)",
            "s23": "风速23出力(kW)",
            "s24": "风速24出力(kW)",
            "s25": "风速25出力(kW)",
            "ppp": "单位功率费用(元/kW)",
        }


class PVP(models.Model):
    """
    太阳能光伏板 Photovoltaic panel
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    max_power = models.FloatField()  # 最大功率
    ppp = models.FloatField(default=0)  # price per power 单位功率费用（元/kWh）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "max_power": "最大功率(W)",
            "ppp": "单位功率费用(元/kW)"
        }


class Buttery(models.Model):
    """
    蓄电池 Buttery
    """
    model_name = models.CharField(max_length=50, unique=True)  # 型号名称
    capacity = models.FloatField()  # 配置容量
    rv = models.FloatField(default=0)  # 额定电压
    uv = models.FloatField(default=0)  # 上行电压
    dv = models.FloatField(default=0)  # 下行电压
    u_cdp = models.FloatField(default=0)  # 充放功率上限
    l_cdp = models.FloatField(default=0)  # 充放功率下限
    u_scr = models.FloatField(default=0)  # 储能占比上限
    l_scr = models.FloatField(default=0)  # 储能占比下限
    effect = models.FloatField(default=0)  # 充放效率
    ppu = models.FloatField(default=0)  # 单位容量价格（元/kWh）
    sp = models.FloatField(default=0)  # 系统投资（元/kW）
    is_default = models.BooleanField(default=False)

    @staticmethod
    def params_info():
        return {
            "model_name": "型号名称",
            "capacity": "配置容量(kWh)",
            "rv": "额定电压(V)",
            "uv": "上行电压(V)",
            "dv": "下行电压(V)",
            "u_cdp": "充放功率上限(kW)",
            "l_cdp": "充放功率下限(kW)",
            "u_scr": "储能占比上限",
            "l_scr": "储能占比下限",
            "effect": "充放效率",
            "ppu": "单位容量价格(元/kWh)",
            "sp": "系统投资(元/kW)"
        }


# 计算结果
class CalResult(models.Model):
    # which = models.CharField(max_length=100)  # 归属
    design_id = models.CharField(max_length=30, default='')  # 设计id
    target_date = models.CharField(max_length=6)  # 日期
    target_time = models.FloatField(default=0)  # 时间点
    ice_os = models.FloatField(default=0)  # CCHP发电
    ice_ig = models.FloatField(default=0)  # 内燃机输入
    gp_ieh = models.FloatField(default=0)  # 地源热泵热耗电
    gp_iec = models.FloatField(default=0)  # 地源热泵冷耗电
    gp_oh = models.FloatField(default=0)  # 地源热泵供热
    gp_oc = models.FloatField(default=0)  # 地源热泵供冷
    ap_ie = models.FloatField(default=0)  # 风冷热泵供冷耗电
    ap_ieh = models.FloatField(default=0)  # 风冷热泵供热耗电
    ap_oh = models.FloatField(default=0)  # 风冷热泵供热
    ar_oh = models.FloatField(default=0)  # 直燃机供热
    ar_oh_p = models.FloatField(default=0)  # 直燃机供热占比
    ap_oh_p = models.FloatField(default=0)  # 风冷热泵供热占比
    ap_oc = models.FloatField(default=0)  # 风冷热泵供冷
    gb_ig = models.FloatField(default=0)  # 燃气锅炉耗气
    gb_oh = models.FloatField(default=0)  # 燃气锅炉供热
    ar_ig = models.FloatField(default=0)  # 直燃型制冷机耗气
    ar_oc = models.FloatField(default=0)  # 直燃型制冷机供冷
    eb_ie = models.FloatField(default=0)  # 电锅炉耗电
    eb_oh = models.FloatField(default=0)  # 电锅炉供热
    it_ch = models.FloatField(default=0)  # 冷水机组耗电
    it_dis = models.FloatField(default=0)  # 冰蓄冷
    ele_buy = models.FloatField(default=0)  # 购电量
    ele_pri = models.FloatField(default=0)  # 购电费用
    gas_buy = models.FloatField(default=0)  # 购气量
    gas_pri = models.FloatField(default=0)  # 购气费用
    heat_buy = models.FloatField(default=0)  # 购热量
    heat_pri = models.FloatField(default=0)  # 购热费用
    ele_sell = models.FloatField(default=0)  # 售电量
    ele_inc = models.FloatField(default=0)  # 收入
    wind = models.FloatField(default=0)  # 风机
    PV = models.FloatField(default=0)  # 光伏板
    cchp_oh = models.FloatField(default=0)  # CCHP供热
    cchp_oc = models.FloatField(default=0)  # CCHP供冷
    is_correct = models.BooleanField(default=True)  # 是否规划成功
    heat_load = models.FloatField(default=0)  # 热负载
    cold_load = models.FloatField(default=0)  # 冷负载
    ele_load = models.FloatField(default=0)  # 电负载
    sell_h = models.FloatField(default=0)  # 售热收益
    sell_c = models.FloatField(default=0)  # 售冷收益
    sell_e = models.FloatField(default=0)  # 售电收益
    wind_power = models.FloatField(default=0)  # 风机出力
    pvp_power = models.FloatField(default=0)  # 光伏出力
    co2_em = models.FloatField(default=0)  # 二氧化碳排放
    nox_em = models.FloatField(default=0)  # 氮氧化物排放
    ele_ch = models.FloatField(default=0)  # 充电功率
    ele_dis = models.FloatField(default=0)  # 放电功率
    ice_store = models.FloatField(default=0)  # 蓄冷量
    heat_store = models.FloatField(default=0)  # 蓄热量
    heat_release = models.FloatField(default=0)  # 放热量
    eru_ele = models.FloatField(default=0)  # 冷机耗电
    eru_oc = models.FloatField(default=0)  # 冷机制冰/供冷
    eru_ie = models.FloatField(default=0)  # 冷机耗电
    ele_soc = models.FloatField(default=0)  # 电池soc
    heat_soc = models.FloatField(default=0)  # 水箱储能状态
    ice_soc = models.FloatField(default=0)  # 冰槽储能状态
    gas_load = models.FloatField(default=0)  # 气负荷
    sell_g = models.FloatField(default=0)  # 售气收益
    error_msg = models.CharField(default="", max_length=100)  # 错误信息


# 配置上限
class ConfigLimit(models.Model):
    design_id = models.CharField(max_length=30, default='', unique=True)  # 设计id
    cchp = models.FloatField(default=0)  # cchp供电出力上限
    gp = models.FloatField(default=0)  # gp输入上限
    ap = models.FloatField(default=0)  # ap输入上限
    gb = models.FloatField(default=0)  # gb输入上限
    ar = models.FloatField(default=0)  # ar输入上限
    eb = models.FloatField(default=0)  # eb输入上限
    ice_ch = models.FloatField(default=0)  # eru输入上限
    ice_dis = models.FloatField(default=0)  # 融冰功率上限
    heat_ch = models.FloatField(default=0)  # 蓄热功率上限
    heat_dis = models.FloatField(default=0)  # 放热攻率上限
    ele_ch = models.FloatField(default=0)  # 电池充放上限
    battery = models.FloatField(default=0)  # 电池容量上限
    wind = models.FloatField(default=0)  # 风机台数上限
    pvp = models.FloatField(default=0)  # 光伏台数上限
    heat_store = models.FloatField(default=0)  # 水箱容量上限
    ice_tank = models.FloatField(default=0)  # 冰槽容量上限


# 设计规划
class DesignPlan(models.Model):
    """
    用户方案表
    """
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    d_name = models.CharField(max_length=50, default='项目名称')  # 方案名称
    d_desc = models.CharField(max_length=100, blank=True, default='')  # 方案描述
    time = models.DateTimeField(default=django.utils.timezone.now)  # 保存日期
    belongs = models.ForeignKey(Users, on_delete=models.DO_NOTHING, default=0)  # 归属人
    model_which = models.IntegerField(default=0)  # 系统配置模式 0:孤岛模式,1:并网不上网,2:并网上网
    opt_target = models.IntegerField(default=0)  # 优化目标：0：经济性；1：能耗性; 2:环境效益
    summer_day = models.CharField(blank=True, default='', max_length=5)  # 典型夏季日
    winter_day = models.CharField(blank=True, default='', max_length=5)  # 典型冬季日
    model_buy_gas = models.BooleanField(default=False)  # 是否买气
    model_buy_heat = models.BooleanField(default=False)  # 是否买热
    gas_max_power = models.FloatField(default=0)  # 气网出力上限
    heat_max_power = models.FloatField(default=0)  # 热网出力上限
    cchp_is_selected = models.BooleanField(default=False)  # cchp是否选中
    cchp_max_power = models.FloatField(default=0)  # cchp最大出力
    cchp_min_power = models.FloatField(default=0)  # cchp最小出力
    ars_is_selected = models.BooleanField(default=False)  # 是否选中烟气热水机
    ars_which = models.CharField(blank=True, default="", max_length=25)  # 烟气热水机型号
    ice_is_selected = models.BooleanField(default=False)  # 内燃机是否选中
    ice_which = models.CharField(blank=True, default="", max_length=25)  # 内燃机型号
    gt_is_selected = models.BooleanField(default=False)  # 燃气轮机是否选中
    gt_which = models.CharField(blank=True, default='', max_length=25)  # 燃气轮机型号
    ar_is_selected = models.BooleanField(default=False)  # 直燃型制冷机是否选中
    ar_which = models.CharField(blank=True, default="", max_length=25)  # 直燃型制冷机型号
    ar_max_power = models.FloatField(default=0)  # 直燃型制冷机出力上限
    ar_min_power = models.FloatField(default=0)  # 直燃型制冷机出力下限
    re_is_selected = models.BooleanField(default=False)  # 可再生能源是否选中
    wind_is_selected = models.BooleanField(default=False)  # 风机是否选中
    wind_which = models.CharField(blank=True, default='', max_length=25)  # 风机型号

    wind_count_max = models.FloatField(default=0)  # 风机台数上限
    wind_count_min = models.FloatField(default=0)  # 风机台数下限

    solar_is_selected = models.BooleanField(default=False)  # 光伏是否选中
    solar_which = models.CharField(blank=True, default='', max_length=25)  # 光伏型号

    pv_count_max = models.FloatField(default=0)  # 光伏台数上限
    pv_count_min = models.FloatField(default=0)  # 光伏台数下限

    hp_is_selected = models.BooleanField(default=False)  # 热泵是否选中
    gp_is_selected = models.BooleanField(default=False)  # 地源热泵是否选中
    gp_which = models.CharField(blank=True, default='', max_length=25)  # 地源热泵型号
    gp_max_power = models.FloatField(default=0)  # 地源热泵最大出力
    gp_min_power = models.FloatField(default=0)  # 地源热泵最小出力
    ap_is_selected = models.BooleanField(default=False)  # 风冷热泵是否选中
    ap_which = models.CharField(blank=True, default='', max_length=25)  # 风冷热泵型号
    ap_max_power = models.FloatField(default=0)  # 风冷热泵最大出力
    ap_min_power = models.FloatField(default=0)  # 风冷热泵最小出力
    boiler_is_selected = models.BooleanField(default=False)  # 锅炉是否选中
    gb_is_selected = models.BooleanField(default=False)  # 燃气锅炉是否选中
    gb_which = models.CharField(blank=True, default='', max_length=25)  # 燃气锅炉型号
    gb_max_power = models.FloatField(default=0)  # 燃气锅炉最大出力
    gb_min_power = models.FloatField(default=0)  # 燃气锅炉最小出力
    eb_is_selected = models.BooleanField(default=False)  # 电锅炉是否选中
    eb_which = models.CharField(blank=True, default='', max_length=25)  # 电锅炉型号
    eb_max_power = models.FloatField(default=0)  # 电锅炉最大出力
    eb_min_power = models.FloatField(default=0)  # 电锅炉最小出力
    ese_is_selected = models.BooleanField(default=False)  # 储能装置是否选中
    ice_storage_is_selected = models.BooleanField(default=False)  # 冰蓄冷装置是否选中
    ice_storage_max_capacity = models.FloatField(default=0)  # 冰蓄冷最大容量
    ice_storage_min_capacity = models.FloatField(default=0)  # 冰蓄冷最小容量
    ice_storage_max_power_ch = models.FloatField(default=0)  # 冰蓄冷充能功率上限
    ice_storage_min_power_ch = models.FloatField(default=0)  # 冰蓄冷充能功率下限

    ice_storage_max_power_dis = models.FloatField(default=0)  # 冰蓄冷放能功率上限
    ice_storage_min_power_dis = models.FloatField(default=0)  # 冰蓄冷放能功率下限
    cu_is_selected = models.BooleanField(default=False)  # 蓄冷机组是否选中
    cu_which = models.CharField(blank=True, default='', max_length=25)  # 冷水机组型号
    it_is_selected = models.BooleanField(default=False)  # 蓄冰槽是否选中
    it_which = models.CharField(blank=True, default='', max_length=25)  # 蓄冰槽型号
    heat_storage_is_selected = models.BooleanField(default=False)  # 储热装置是否选中
    heat_storage_max_capacity = models.FloatField(default=0)  # 储热最大容量
    heat_storage_min_capacity = models.FloatField(default=0)  # 储热最小容量
    heat_storage_max_powerch = models.FloatField(default=0)  # 充能功率上限
    heat_storage_max_powerdis = models.FloatField(default=0)  # 放能功率上限

    heat_storage_min_powerch = models.FloatField(default=0)  # 充能功率下限
    heat_storage_min_powerdis = models.FloatField(default=0)  # 放能功率下限
    heat_storage_efficiency = models.FloatField(default=0)  # 储热效率
    heat_storage_investment = models.FloatField(default=0)  # 单位功率投资(元/kWh)
    ele_storage_is_selected = models.BooleanField(default=False)  # 储电设备是否选中
    ele_storage_max_capacity = models.FloatField(default=0)  # 储电设备最大容量
    ele_storage_min_capacity = models.FloatField(default=0)  # 储电设备最小容量
    ele_storage_max_powerch = models.FloatField(default=0)  # 储电设备充放功率上限
    ele_storage_max_powerdis = models.FloatField(default=0)  # 储电设备充放功率下限
    battery_is_selected = models.BooleanField(default=False)  # 是否选中电池
    battery_which = models.CharField(blank=True, default='', max_length=25)  # 电池型号

    # 算法参数
    pop_size = models.FloatField(default=0)  # 种群规模
    c1 = models.FloatField(default=0)  # 个体学习因子C1
    c2 = models.FloatField(default=0)  # 个体学习因子C2
    inertia_weight = models.FloatField(default=0)  # 惯性权重
    iter_max_num = models.FloatField(default=0)  # 最大迭代次数
    fly_speed = models.FloatField(default=0)  # 最大飞行速度占问题空间百分比
    residual = models.FloatField(default=0)  # 收敛残差
    # =====================


# 经评参数
class EconomicParams(models.Model):
    loan_ratio = models.FloatField(default=50)  # 贷款比例（%）
    capital_ratio = models.FloatField(default=50)  # 资本金比例（%）
    lending_rates = models.FloatField(default=50)  # 贷款利率（%）
    liquidity_ratio = models.FloatField(default=50)  # 流动资金比例（%）
    depreciation_period = models.FloatField(default=50)  # 折旧年限
    residual_rate = models.FloatField(default=50)  # 残值率（%）
    reserve_rate = models.FloatField(default=50)  # 工程预备费率（%）
    e_vat = models.FloatField(default=50)  # 售电增值税税率（%）
    hc_vat = models.FloatField(default=50)  # 冷热增值税税率（%）
    cgccf = models.FloatField(default=50)  # 施工总承包建筑工程费费率（%）
    cgcepf = models.FloatField(default=50)  # 施工总承包设备购置费费率（%）
    cgcief = models.FloatField(default=50)  # 施工总承包安装工程费费率（%）
    cgcof = models.FloatField(default=50)  # 施工总承包其它费用费率（%）
    scesf = models.FloatField(default=50)  # 系统调试费设备规模系数
    apia = models.FloatField(default=50)  # 无形资产摊销年限


# 优化计算配置方案
class OptConfig(models.Model):
    opt_id = models.CharField(max_length=50, default='', unique=True)  # 优化配置id
    opt_name = models.CharField(max_length=50, default='优化配置')  # 优化名称
    opt_desc = models.CharField(max_length=100, blank=True, default='')  # 方案描述
    predict_date = models.CharField(blank=True, default='', max_length=5)  # 预测日期
    time = models.DateTimeField(default=django.utils.timezone.now)  # 保存日期
    belongs = models.ForeignKey(Users, on_delete=models.DO_NOTHING, default=0)  # 归属人
    model_which = models.IntegerField(default=0)  # 系统配置模式 0:孤岛模式,1:并网不上网,2:并网上网
    power_ensure_rate = models.FloatField(default=0)  # 孤岛模式下:电负荷保证率
    heat_ensure_rate = models.FloatField(default=0)  # 孤岛模式下:热负荷保证率
    cold_ensure_rate = models.FloatField(default=0)  # 孤岛模式下:冷负荷保证率
    model_buy_gas = models.BooleanField(default=False)  # 是否买气
    model_buy_heat = models.BooleanField(default=False)  # 是否买热
    gas_max_output = models.IntegerField(default=0)  # 气网出力上限
    heat_max_output = models.IntegerField(default=0)  # 热网出力上限
    cchp_is_selected = models.BooleanField(default=False)  # cchp是否选中
    cchp_max_power = models.FloatField(default=0)  # cchp最大出力
    ars_is_selected = models.BooleanField(default=False)  # 是否选中烟气热水机
    ars_which = models.CharField(blank=True, default="", max_length=25)  # 烟气热水机型号
    ars_count = models.IntegerField(blank=True, default=0)  # 烟气热水机台数
    ice_is_selected = models.BooleanField(default=False)  # 内燃机是否选中
    ice_which = models.CharField(blank=True, default="", max_length=25)  # 内燃机型号
    ice_count = models.IntegerField(blank=True, default=0)  # 内燃机台数
    gt_is_selected = models.BooleanField(default=False)  # 燃气轮机是否选中
    gt_which = models.CharField(blank=True, default='', max_length=25)  # 燃气轮机型号
    gt_count = models.IntegerField(blank=True, default=0)  # 燃气轮机台数
    ar_is_selected = models.BooleanField(default=False)  # 直燃型制冷机是否选中
    ar_which = models.CharField(blank=True, default="", max_length=25)  # 直燃型制冷机型号
    ar_count = models.IntegerField(blank=True, default=0)  # 直燃型制冷机台数
    re_is_selected = models.BooleanField(default=False)  # 可再生能源是否选中
    wind_is_selected = models.BooleanField(default=False)  # 风机是否选中
    wind_which = models.CharField(blank=True, default='', max_length=25)  # 风机型号
    wind_count = models.IntegerField(blank=True, default=0)  # 风机台数
    solar_is_selected = models.BooleanField(default=False)  # 光伏是否选中
    solar_which = models.CharField(blank=True, default='', max_length=25)  # 光伏型号
    solar_count = models.IntegerField(blank=True, default=0)  # 光伏台数
    hp_is_selected = models.BooleanField(default=False)  # 热泵是否选中
    gp_is_selected = models.BooleanField(default=False)  # 地源热泵是否选中
    gp_which = models.CharField(blank=True, default='', max_length=25)  # 地源热泵型号
    gp_count = models.IntegerField(blank=True, default=0)  # 地源热泵台数
    ap_is_selected = models.BooleanField(default=False)  # 风冷热泵是否选中
    ap_which = models.CharField(blank=True, default='', max_length=25)  # 风冷热泵型号
    ap_count = models.IntegerField(blank=True, default=0)  # 风冷热泵台数
    boiler_is_selected = models.BooleanField(default=False)  # 锅炉是否选中
    gb_is_selected = models.BooleanField(default=False)  # 燃气锅炉是否选中
    gb_which = models.CharField(blank=True, default='', max_length=25)  # 燃气锅炉型号
    gb_count = models.IntegerField(blank=True, default=0)  # 燃气锅炉台数
    eb_is_selected = models.BooleanField(default=False)  # 电锅炉是否选中
    eb_which = models.CharField(blank=True, default='', max_length=25)  # 电锅炉型号
    eb_count = models.IntegerField(blank=True, default=0)  # 电锅炉台数
    ese_is_selected = models.BooleanField(default=False)  # 储能装置是否选中
    ice_storage_is_selected = models.BooleanField(default=False)  # 冰蓄冷装置是否选中

    cu_is_selected = models.BooleanField(default=False)  # 蓄冷机组是否选中
    cu_which = models.CharField(blank=True, default='', max_length=25)  # 冷水机组型号
    cu_count = models.IntegerField(blank=True, default=0)  # 冷水机组台数
    it_is_selected = models.BooleanField(default=False)  # 蓄冰槽是否选中
    it_which = models.CharField(blank=True, default='', max_length=25)  # 蓄冰槽型号
    it_count = models.IntegerField(blank=True, default=0)  # 蓄冰槽台数
    heat_storage_is_selected = models.BooleanField(default=False)  # 储热装置是否选中
    heat_storage_max_capacity = models.FloatField(default=0)  # 储热最大容量
    heat_storage_max_powerch = models.FloatField(default=0)  # 充能功率
    heat_storage_max_powerdis = models.FloatField(default=0)  # 放能功率
    heat_storage_efficiency = models.FloatField(default=0)  # 储热效率
    ele_storage_is_selected = models.BooleanField(default=False)  # 储电设备是否选中

    battery_is_selected = models.BooleanField(default=False)  # 是否选中电池
    battery_which = models.CharField(blank=True, default='', max_length=25)  # 电池型号
    battery_count = models.IntegerField(blank=True, default=0)  # 电池个数


# 优化计算结果
class OptResult(models.Model):
    opt_id = models.CharField(max_length=30, default='')  # 设计id
    target_date = models.CharField(max_length=6)  # 日期
    target_time = models.FloatField(default=0)  # 时间点
    ice_os = models.FloatField(default=0)  # CCHP发电
    ice_ig = models.FloatField(default=0)  # 内燃机输入
    gp_ieh = models.FloatField(default=0)  # 地源热泵耗电
    gp_oh = models.FloatField(default=0)  # 地源热泵供热
    gp_oc = models.FloatField(default=0)  # 地源热泵供冷
    ap_ie = models.FloatField(default=0)  # 风冷热泵耗电
    ap_oc = models.FloatField(default=0)  # 风冷热泵供冷
    gb_ig = models.FloatField(default=0)  # 燃气锅炉耗气
    gb_oh = models.FloatField(default=0)  # 燃气锅炉供热
    ar_ig = models.FloatField(default=0)  # 直燃型制冷机耗气
    ar_oc = models.FloatField(default=0)  # 直燃型制冷机供冷
    eb_ie = models.FloatField(default=0)  # 电锅炉耗电
    eb_oh = models.FloatField(default=0)  # 电锅炉供热
    it_ch = models.FloatField(default=0)  # 冷水机组耗电
    it_dis = models.FloatField(default=0)  # 冰蓄冷
    ele_buy = models.FloatField(default=0)  # 购电量
    ele_pri = models.FloatField(default=0)  # 购电费用
    gas_buy = models.FloatField(default=0)  # 购气量
    gas_pri = models.FloatField(default=0)  # 购气费用
    heat_buy = models.FloatField(default=0)  # 购热量
    heat_pri = models.FloatField(default=0)  # 购热费用
    ele_sell = models.FloatField(default=0)  # 售电量
    ele_inc = models.FloatField(default=0)  # 收入
    wind = models.FloatField(default=0)  # 风机
    PV = models.FloatField(default=0)  # 光伏板
    cchp_oh = models.FloatField(default=0)  # CCHP供热
    cchp_oc = models.FloatField(default=0)  # CCHP供冷
    is_correct = models.BooleanField(default=True)  # 是否规划成功
    heat_load = models.FloatField(default=0)  # 热负载
    cold_load = models.FloatField(default=0)  # 冷负载
    ele_load = models.FloatField(default=0)  # 电负载
    sell_h = models.FloatField(default=0)  # 售热收益
    sell_c = models.FloatField(default=0)  # 售冷收益
    sell_e = models.FloatField(default=0)  # 售电收益
    wind_power = models.FloatField(default=0)  # 风机出力
    pvp_power = models.FloatField(default=0)  # 光伏出力
    co2_em = models.FloatField(default=0)  # 二氧化碳排放
    nox_em = models.FloatField(default=0)  # 氮氧化物排放
    ele_ch = models.FloatField(default=0)  # 充电功率
    ele_dis = models.FloatField(default=0)  # 放电功率
    ice_store = models.FloatField(default=0)  # 蓄冷量
    heat_store = models.FloatField(default=0)  # 蓄热量
    heat_release = models.FloatField(default=0)  # 放热量
    ice_dis = models.FloatField(default=0)  # 融冰
    eru_ele = models.FloatField(default=0)  # 冷水机组耗电
    eru_c = models.FloatField(default=0)  # 冷水机组制冷


# ====================新计算架构的表格，暂时忽略====================
# 负载数据
class LoadParams(models.Model):
    """
    负载表，用于存储某一次规划的负载数据
    仅供数据计算期间提供数据，计算完成后会进行清空操作
    """
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    hour = models.IntegerField(default=0)  # 小时数
    head_load = models.FloatField(default=0)  # 热负载
    cold_load = models.FloatField(default=0)  # 冷负载
    ele_load = models.FloatField(default=0)  # 电负载
    gas_load = models.FloatField(default=0)  # 气负载


# 能源购买的单价
class EnergyPurchase(models.Model):
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    hour = models.IntegerField(default=0)  # 小时数
    power = models.FloatField(default=0)  # 电价
    gas = models.FloatField(default=0)  # 气价
    heat = models.FloatField(default=0)  # 热价


# 能源售卖至用户
class EnergySale2C(models.Model):
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    hour = models.IntegerField(default=0)  # 小时数
    power = models.FloatField(default=0)  # 电价
    heat = models.FloatField(default=0)  # 热价
    cold = models.FloatField(default=0)  # 冷价


# 能源售卖至企业（电网）
class EnergySale2B(models.Model):
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    hour = models.IntegerField(default=0)  # 小时数
    power = models.FloatField(default=0)  # 电价


# 风资源数据
class WindLoad(models.Model):
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    hour = models.IntegerField(default=0)  # 小时数
    speed = models.FloatField(default=0)  # 风速


# 光资源数据
class LightLoad(models.Model):
    design_id = models.CharField(max_length=50, default='', unique=True)  # 方案id
    hour = models.IntegerField(default=0)  # 小时数
    pv = models.FloatField(default=0)  # 实际光伏照度
